<template>
    <div>
        <h2>用户登录</h2>
        <table class="table table-bordered">
            <tbody>

                <tr>
                    <td align="right">用户账号</td>
                    <td><input type="text" v-model="info.Name"/></td>
                </tr>

                <tr>
                    <td align="right">密码</td>
                    <td><input type="password" v-model="info.Password"/> </td>
                </tr>

                
                <tr>
                    <td align="right"></td>
                    <td>
                        <input type="button" value="登录" class="btn btn-info" @click="ok"/>
                        
                    </td>
                </tr>


            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,reactive} from 'vue'
import axios from 'axios';
import { useRouter,useRoute } from 'vue-router';
import {useUserStore} from '@/stores/user'

let router = useRouter();
let route = useRoute();

const a = useUserStore();

let info:any = reactive({
    Name:'',
    Password:''
})


const ok = ()=>{
    if(info.Name == "")
    {
        alert('用户账号不能为空');
        return;
    }
    if(info.Password == "")
    {
        alert('密码不能为空');
        return;
    }

    axios({
        url:'http://localhost:5214/api/House/AddAdmin',
        method:'post',
        params:info
    })
    .then((res)=>{
        if(res.data == 0)
        {
            alert('用户账号不存在');
            return;
        }
        else if(res.data == -1)
        {
            alert('密码错误');
            return;
        }
        else
        {
            alert('登陆成功');
            a.userInfo = res.data;
        }
    })
    .catch((err)=>{
        console.log(err);
    })







}








</script>

<style scoped>

</style>